#include <gtk/gtk.h>

#include "post.h"
#include "postwin.h"

struct _Post
{
  GtkApplication parent;
};

G_DEFINE_TYPE(Post, post, GTK_TYPE_APPLICATION);

static void
post_init (Post *app)
{
}


static void
post_startup (GApplication *app)
{
  G_APPLICATION_CLASS (post_parent_class)->startup (app);
}

static void
post_activate (GApplication *app)
{
  PostWindow *win;

  win = post_window_new (EXAMPLE_APP (app));
  gtk_window_present (GTK_WINDOW (win));
}

static void
post_open (GApplication  *app,
                  GFile        **files,
                  gint           n_files,
                  const gchar   *hint)
{
  GList *windows;
  PostWindow *win;
  int i;

  windows = gtk_application_get_windows (GTK_APPLICATION (app));
  if (windows)
    win = EXAMPLE_APP_WINDOW (windows->data);
  else
    win = post_window_new (EXAMPLE_APP (app));

  for (i = 0; i < n_files; i++)
    post_window_open (win, files[i]);

  gtk_window_present (GTK_WINDOW (win));
}

static void
post_class_init (PostClass *class)
{
  G_APPLICATION_CLASS (class)->startup = post_startup;
  G_APPLICATION_CLASS (class)->activate = post_activate;
  G_APPLICATION_CLASS (class)->open = post_open;
}

Post *
post_new (void)
{
  return g_object_new (EXAMPLE_APP_TYPE,
                       "application-id", "org.gtk.post",
                       "flags", G_APPLICATION_HANDLES_OPEN,
                       NULL);
}
